package edu.cug.water.crawler.analyze.service.impl;


import edu.cug.water.crawler.analyze.service.EsAnalyzeService;
import edu.cug.water.crawler.common.utils.EsUtils;
import org.frameworkset.elasticsearch.entity.ESDatas;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EsAnalyzeServiceImpl implements EsAnalyzeService {


    @Autowired
    EsUtils esUtils;

    @Override
    public Map<String, Object> getAnalyzeData(String indexName, String field1, String field2) {
        ESDatas<?> aggsDaTaGeneral = null;

        if (field2 == null) {
            aggsDaTaGeneral = esUtils.getOneAggsDaTaGeneral(indexName, field1);
            return esUtils.parseOneAggs(aggsDaTaGeneral);
        }

        aggsDaTaGeneral = esUtils.getAggsDaTaGeneral(indexName, field1, field2);

        return esUtils.getMap(aggsDaTaGeneral);
    }

    @Override
    public List getDataByStationCodes(List<String> stationCodes) {
        ESDatas<?> data = esUtils.getDataByStationCode(stationCodes);
        return data.getDatas();
    }

    @Override
    public List getDataByCroSectionOfRivers(List<String> stationCodes) {
        ESDatas<?> data = esUtils.getDataByCroSectionOfRivers(stationCodes);
        return data.getDatas();
    }
}
